package com.kl.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kl.domain.LogisticsStoreDTOS;
import com.kl.domain.WaybillDTO;
import com.kl.em.ConstantEnum;
import com.kl.em.Result;
import com.kl.entity.LogisticsStore;
import com.kl.feign.OrderServcieFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-11-02
 */
@RestController
@RequestMapping("/waybill")
@Api(value = "网点查询接口")
public class WaybillController {

    @Autowired
    private OrderServcieFeign orderServcieFeign;

    @ApiOperation(value = "运单号查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "waybill_id", value = "运单号", required = false, paramType = "query"),

    })
    @GetMapping("/id")
    public Result<LogisticsStoreDTOS> findBywaybillId(@RequestParam Long waybill_id) {
        //调用运单查询接口
        Result<WaybillDTO> waybillDTOResult = orderServcieFeign.selectById(waybill_id);
        if(waybillDTOResult==null){
            return Result.build(ConstantEnum.RETURNNULL);
        }
        return Result.build(ConstantEnum.SUCCESS).setResult(waybillDTOResult);
    }
    @ApiOperation(value = "手机号查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "consigneePhone", value = "手机号", required = false, paramType = "query"),
    })
    @GetMapping("/phone")
    public Result<LogisticsStoreDTOS> findByPhone(@RequestParam String consigneePhone) {
        //调用运单查询接口
        Result<List<WaybillDTO>> waybillByPhone = orderServcieFeign.findWaybillByPhone(consigneePhone);
        if(waybillByPhone==null){
            return Result.build(ConstantEnum.RETURNNULL);
        }
        return Result.build(ConstantEnum.SUCCESS).setResult(waybillByPhone);
    }
}
